home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1994 January / PSL Monthly Shareware CD-ROM (Public Software Library) (January 1994).iso / games / dos / board / chkr_pf.com / CHECKERS.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1990-03-14  |  22.0 KB  |  792 lines

  1.  
  2. Program Checkers;
  3.  
  4. Uses graph,crt,egadrv;  {egadrv is unit containing BGI driver}
  5.  
  6. (*                                                  *)
  7. (*    A Proper Game of Draughts                     *)
  8. (*                                                  *)
  9. (*      Based on a program by Tim Hartnell          *)
  10. (*    in Getting Acquainted With Your ZX81,         *)
  11. (*       Creative Computing Press,1982.             *)
  12. (*                                                  *)
  13. (*   Board algorithm from Scientific Amer article.  *)
  14. (*                                                  *)
  15. (*     Requires EGA card                            *)
  16. (*                                                  *)
  17. (*    Peter Franchuk    3/2/90                      *)
  18. (*       CIS ID [74146,225]                         *)
  19. (*                                                  *)
  20. (*                                                  *)
  21. (*   Released to Public Domain                      *)
  22. (*     for Personal use ONLY                        *)
  23. (*                                                  *)
  24.  
  25. Const
  26.   GDDrv='';   {for BGI driver if not registered}
  27.   Direc:array[1..4] of integer=(-6,-7,6,7);
  28.  
  29. Type
  30.   Pieces=(HuKing,HuMan,Blnk,CoMan,CoKing,OffBrd);
  31.   Moverec=record
  32.     row,col,value : integer;
  33.     piece:pieces;
  34.    end;
  35.  
  36. Var
  37.   A : array [10..86] of Pieces;           {work array for pieces}
  38.   Board : array [1..8,1..8] of byte;      {indices of squares--used for move}
  39.   Use,Checker : array [1..12] of integer; {keep track of comp pieces location}
  40.   jmpchk : array [24..72] of boolean;     {used to check for jumps}
  41.   HuMove,Hufirst,Nmove,Njmp : boolean;
  42.   HuName : string[10];
  43.   PiecePtr : array [HuKing..CoKing] of pointer;  {images of pieces}
  44.   FmSq,ToSq : Moverec;
  45.   Total,Sum,Compcnt,KingCnt : word;
  46.   ans : char;
  47.   HuPiece,CoPiece : set of Pieces;
  48.  
  49. Procedure Set_Board;
  50.   Var
  51.     i,j,indx : integer;
  52.     sqval : byte;
  53.     strt : array [1..8] of byte;
  54.   Begin
  55.     HuPiece := [HuKing,HuMan];
  56.     CoPiece := [CoKing,CoMan];
  57.     for indx := 10 to 86 do A[indx] := offbrd;
  58.     compcnt := 0;
  59.     for indx := 69 to 72 do           {load up array with pieces}
  60.      begin
  61.       a[indx] := CoMan;
  62.       inc(compcnt);checker[compcnt] := indx;
  63.      end;
  64.     for indx := 63 to 66 do
  65.      begin
  66.       a[indx] := Coman;
  67.       inc(compcnt);checker[compcnt] := indx;
  68.      end;
  69.     for indx := 56 to 59 do
  70.      begin
  71.       a[indx] := Coman;
  72.       inc(compcnt);checker[compcnt] := indx;
  73.      end;
  74.     for indx := 50 to 53 do a[indx] := blnk;
  75.     for indx := 43 to 46 do a[indx] := blnk;
  76.     for indx := 37 to 40 do a[indx] := HuMan;
  77.     for indx := 30 to 33 do a[indx] := HuMan;
  78.     for indx := 24 to 27 do a[indx] := Human;
  79.     for i := 1 to 8 do for j := 1 to 8 do board[i,j] := 0;
  80.     strt[1] := 72;strt[2] := 66;strt[3] := 59;
  81.     strt[4] := 53;strt[5] := 46;
  82.     strt[6] := 40;strt[7] := 33;strt[8] := 27;
  83.     for i := 1 to 8 do
  84.      begin
  85.       if odd(i)
  86.        then j := 2
  87.        else j := 1;                    {load up board image}
  88.       sqval := strt[i];
  89.       while j<9 do
  90.        begin
  91.         board[i,j] := sqval;
  92.         dec(sqval);inc(j,2);
  93.        end;
  94.      end;
  95.     for i := 24 to 72 do jmpchk[i] := false;
  96.     compcnt := 12;
  97.     KingCnt := 0;
  98.     total := 0;                        {initialize rest}
  99.     sum := 0;
  100.   End;
  101.  
  102. Procedure Draw_info;
  103.   Var
  104.     i,j : integer;
  105.     ityp : pieces;
  106.     Gd,Gm : integer;
  107.     imsze : word;
  108.   Begin
  109.     SetFillStyle(SolidFill,LightRed);
  110.     if Hufirst
  111.      then j := 50
  112.      else j := 300;
  113.     i := 450;                          {draw and save checker images}
  114.     FillEllipse(i,j,12,9);
  115.     circle(i,j,9);circle(i,j,4);
  116.     if Hufirst
  117.      then j := 300
  118.      else j := 50;
  119.     i := 450;
  120.     circle(i,j,12);circle(i,j,9);circle(i,j,4);
  121.     imsze := Imagesize(1,1,33,25);
  122.     for ityp := HuKing to CoKing do getmem(pieceptr[ityp],imsze);
  123.     GetImage(434,38,466,62,pieceptr[CoMan]^);
  124.     GetImage(1,1,33,25,pieceptr[blnk]^);
  125.     GetImage(434,288,466,312,pieceptr[HuMan]^);
  126.     j := 158;
  127.     if Hufirst
  128.      then i := 434
  129.      else i := 334;
  130.     GetImage(i,j,i+32,j+24,pieceptr[HuKing]^);
  131.     if Hufirst
  132.      then i := 334
  133.      else i := 434;
  134.     GetImage(i,j,i+32,j+24,pieceptr[CoKing]^);
  135.     OuttextXY(330,50,'Computer');
  136.     OutTextXY(330,300,HuName);
  137.   End;
  138.  
  139. Procedure Who_first;
  140.   Var
  141.     ans,prmpt : char;
  142.     Gd,Gm :integer;
  143.     sx,sy :integer;
  144.   Begin
  145.     if registerBGIdriver(@EGAVGADriverProc)<0 then halt;
  146.   {
  147.      if not registering driver, comment out line above and be sure to have
  148.       GdGrv constant defined to path of BGI driver at beginning of program.
  149.   }
  150.     Gd := EGA;Gm := EGAHi;
  151.     Initgraph(gd,gm,gddrv);
  152.     OutTextXY(362,130,'Checkers');
  153.     SetFillStyle(SolidFill,LightRed);
  154.     FillEllipse(350,170,12,9);
  155.     OuttextXY(346,167,'K');
  156.     circle(350,170,10);
  157.     Circle(450,170,12);Circle(450,170,10);
  158.     OuttextXY(446,167,'K');
  159.     MoveTo(40,170);
  160.     OutText('Your name, please : ');
  161.     sx := GetX;sy := getY;
  162.     ans := ' ';HuName := '';prmpt := '_';
  163.     SetFillstyle(emptyfill,black);
  164.     Repeat
  165.      Bar(sx,sy,sx+80,sy+10);
  166.      MoveTo(sx,sy);OutText(HuName+prmpt);
  167.      Ans := readKey;
  168.      if ans>#31
  169.       then HuName := HuName+ans
  170.       else if ans=#8 then HuName := copy(HuName,1,length(HuName)-1);
  171.      HuName[1] := Upcase(HuName[1]);
  172.     Until ans=#13;
  173.     Bar(sx,sy,sx+80,sy+10);
  174.     OutTextXY(sx,sy,HuName);
  175.     OutTextXY(40,185,'Will you go first, '+HuName+' ? ');
  176.     ans := ReadKey;
  177.     HuFirst := ans in ['Y','y'];
  178.     Draw_info;
  179.     HuMove := Hufirst;
  180.   End;
  181.  
  182. Procedure Draw_Board;
  183.   Var cor,i,y :integer;
  184.   Begin
  185.     SetViewPort(36,65,334,311,ClipOn);
  186.     SetFillstyle(Solidfill,Red);
  187.     SetLinestyle(SolidLn,0,Thickwidth);
  188.     SetColor(brown);
  189.     bar(1,1,288,224);
  190.     rectangle(1,1,288,224);
  191.     cor := 28;y := 36;
  192.     for i := 1 to 7 do
  193.      begin
  194.       line(y,0,y,224);                  {initial board}
  195.       line(0,cor,288,cor);
  196.       inc(cor,28);inc(y,36);
  197.      end;
  198.     for i := 1 to 3 do
  199.      begin
  200.       if odd(i)
  201.        then cor := 2
  202.        else cor :=1;
  203.       while cor<9 do
  204.        begin
  205.         PutImage((cor-1)*36+2,(i-1)*28+2,pieceptr[CoMan]^,NormalPut);
  206.         inc(cor,2);
  207.        end;
  208.      end;
  209.     for i := 4 to 5 do
  210.      begin
  211.       if odd(i)
  212.        then cor := 2
  213.        else cor :=1;
  214.       while cor<9 do
  215.        begin
  216.         PutImage((cor-1)*36+2,(i-1)*28+2,pieceptr[Blnk]^,NormalPut);
  217.         inc(cor,2);
  218.        end;
  219.      end;
  220.     for i := 6 to 8 do
  221.      begin
  222.       if odd(i)
  223.        then cor := 2
  224.        else cor :=1;
  225.       while cor<9 do
  226.        begin
  227.         PutImage((cor-1)*36+2,(i-1)*28+2,pieceptr[HuMan]^,NormalPut);
  228.         inc(cor,2);
  229.        end;
  230.      end;
  231.     SetFillStyle(emptyFill,black);
  232.     SetViewport(0,0,639,349,clipon);
  233.     i := 50;y := 55; ans := '1';
  234.     for cor := 1 to 8 do
  235.      begin
  236.       OutTextXY(i,y,ans);
  237.       OutTextXY(i,295,ans);
  238.       inc(i,36);ans := char( ord(ans) + 1);
  239.      end;
  240.     i := 24;y:=75; ans := 'A';
  241.     for cor := 1 to 8 do
  242.      begin
  243.       OutTextXY(i,y,ans);
  244.       inc(y,28);ans := char( ord(ans) +1);
  245.      end;
  246.     SetColor(white);
  247.   End;
  248.  
  249. Procedure PlacePiece(v:integer;p:pieces);
  250.   Var r,c:integer;
  251.   Begin
  252.      case v of
  253.       72 : begin r := 1; c := 2 end;   27 : begin r := 8; c := 1 end;
  254.       71 : begin r := 1; c := 4 end;   26 : begin r := 8; c := 3 end;
  255.       70 : begin r := 1; c := 6 end;   25 : begin r := 8; c := 5 end;
  256.       69 : begin r := 1; c := 8 end;   24 : begin r := 8; c := 7 end;
  257.       66 : begin r := 2; c := 1 end;   59 : begin r := 3; c := 2 end;
  258.       65 : begin r := 2; c := 3 end;   58 : begin r := 3; c := 4 end;
  259.       64 : begin r := 2; c := 5 end;   57 : begin r := 3; c := 6 end;
  260.       63 : begin r := 2; c := 7 end;   56 : begin r := 3; c := 8 end;
  261.       53 : begin r := 4; c := 1 end;   46 : begin r := 5; c := 2 end;
  262.       52 : begin r := 4; c := 3 end;   45 : begin r := 5; c := 4 end;
  263.       51 : begin r := 4; c := 5 end;   44 : begin r := 5; c := 6 end;
  264.       50 : begin r := 4; c := 7 end;   43 : begin r := 5; c := 8 end;
  265.       40 : begin r := 6; c := 1 end;   33 : begin r := 7; c := 2 end;
  266.       39 : begin r := 6; c := 3 end;   32 : begin r := 7; c := 4 end;
  267.       38 : begin r := 6; c := 5 end;   31 : begin r := 7; c := 6 end;
  268.       37 : begin r := 6; c := 7 end;   30 : begin r := 7; c := 8 end;
  269.       end;
  270.     SetViewPort(36,65,334,311,ClipOn);
  271.     PutImage((c-1)*36+2,(r-1)*28+2,pieceptr[p]^,NormalPut);
  272.     a[v] := p;
  273.     SetViewPort(0,0,639,349,ClipOn);
  274.   End;
  275.  
  276. Procedure Flash_piece(where:integer);
  277.   Var ct,nb: integer;cpiece : pieces;
  278.   Begin
  279.    cpiece := a[where];
  280.    if cpiece in HuPiece
  281.     then nb := 2
  282.     else nb := 4;
  283.    for ct := 1 to nb do
  284.     begin
  285.      placepiece(where,blnk);
  286.      delay(200);
  287.      placepiece(where,cpiece);
  288.      delay(100);
  289.     end;
  290.   End;
  291.  
  292. Procedure OpChkJmp(var Q:integer;z:integer);
  293.   Var d : integer;
  294.   Begin
  295.     for d := 1 to 4 do                     {player piece can jump?}
  296.     begin
  297.      if (a[z]<>HuKing) and (d>2) then exit;
  298.      if (a[z-direc[d]] in CoPiece) and (a[z-2*direc[d]]=blnk)
  299.       then begin
  300.        Q := direc[d];
  301.        exit;
  302.       end;
  303.     end;
  304.     Q := 0;
  305.   End;
  306.  
  307.  
  308. Procedure Player_move(var newmve : boolean);
  309.   var
  310.     rw,cl,j,i : integer;
  311.     k1,k2 : char;
  312.     good : boolean;
  313.  
  314.   Procedure Showmove;
  315.     Begin
  316.      flash_piece(fmsq.value);
  317.      placePiece(fmsq.value,blnk);
  318.      placePiece(tosq.value,fmsq.piece);
  319.     End;
  320.  
  321.   Begin
  322.     good := false;
  323.     Setcolor(black);
  324.     bar(335,90,630,270);
  325.     Setcolor(white);
  326.     OutTextXY(350,110,'Your move, '+HuName);
  327.     if not newmve then
  328.      begin
  329.       j := 0;                        {can you really continue jump?}
  330.       Opchkjmp(j,tosq.value);
  331.       if j=0 then
  332.        begin
  333.         newmve := true;
  334.         HuMove := false;
  335.         exit;                        {you lied}
  336.        end;
  337.      end;
  338.     if newmve
  339.      then outtextxy(350,120,'Specifiy letter,number (or [ESC])')
  340.      else outtextxy(355,120,'Continue your jump');
  341.     repeat
  342.      moveto(365,130);
  343.      Outtext('Move from : ');
  344.      bar(getx,130,550,140);
  345.      if newmve
  346.       then begin
  347.         k1 := ' ';
  348.         repeat
  349.         k1 := upcase(readkey);
  350.         until ((k1>='A') and (k1<='H')) or (k1=#27);
  351.       end
  352.       else k1 := char( tosq.row-1+ord('A') );
  353.      bar(335,140,630,200);
  354.      if k1=#27 then
  355.       begin
  356.        OutTextXY(340,150,'OK, GoodBye');
  357.        delay(1500);
  358.        closegraph;
  359.        halt;
  360.       end;
  361.      Outtext(k1);
  362.      rw := ord(k1)-ord('A') + 1;
  363.      if newmve
  364.       then begin
  365.        k2 := ' ';
  366.        repeat
  367.        k2 := Readkey;
  368.        until (k2>='1') and (k2<='8');
  369.       end
  370.       else k2 := char( tosq.col-1+ord('1') );
  371.      outtext(k2);
  372.      cl := ord(k2)-ord('1')+1;
  373.      good := ( odd(rw) and (not odd(cl)) ) or ( (not odd(rw)) and odd(cl) );
  374.      if not good then outtextXY(380,170,'You can''t do that');
  375.      if good then
  376.       begin
  377.        FmSq.row := rw;FmSq.col := cl;
  378.        Fmsq.value := Board[rw,cl];fmsq.piece := a[fmsq.value];
  379.       end;
  380.      if good then
  381.       begin
  382.        outtext(' to: ');
  383.        k1 := ' ';
  384.        repeat
  385.        k1 := upcase(readkey);
  386.        until (k1>='A') and (k1<='H');
  387.        Outtext(k1);
  388.        rw := ord(k1)-ord('A') + 1;
  389.        k2 := ' ';
  390.        repeat
  391.        k2 := Readkey;
  392.        until (k2>='1') and (k2<='8');
  393.        outtext(k2);
  394.        cl := ord(k2)-ord('1')+1;
  395.       end;
  396.      good := (odd(rw) and (not odd(cl))) or ((not odd(rw)) and odd(cl));
  397.  
  398.      if not good then outtextXY(380,170,'You can''t do that');
  399.  
  400.      if good then
  401.       begin
  402.        toSq.row := rw;toSq.col := cl;
  403.        tosq.value := Board[rw,cl];tosq.piece := a[tosq.value];
  404.       end;
  405.  
  406.      if good and jmpchk[fmsq.value] and (abs(fmsq.value-tosq.value)<=7)
  407.       then begin
  408.        good := false;
  409.        OutTextXY(340,160,'You must make the jump.');
  410.       end;
  411.  
  412.      if good and (fmsq.piece=Human) then begin
  413.       good := (tosq.value-fmsq.value) > 0;
  414.       if not good then outtextXY(380,170,'Only Kings move backwards');
  415.       end;
  416.  
  417.      if good then begin
  418.        good:=((fmsq.piece=human) or (fmsq.piece=huKing)) and (tosq.piece=blnk);
  419.        if not good then
  420.         begin outtextXY(340,180,'You must move YOUR man');
  421.         outtextXY(340,190,' to an adjacent free space');end;
  422.        end;
  423.  
  424.      if good then begin
  425.        good := ( (abs(fmsq.value-tosq.value) mod 6)=0 ) or
  426.         ( (abs(fmsq.value-tosq.value) mod 7)=0 );
  427.        if not good then outtextXY(380,170,'Must move on the diagonal');
  428.        end;
  429.  
  430.      if good and (abs(fmsq.value-tosq.value)>7) then begin
  431.        good := a[ (fmsq.value+tosq.value) div 2 ] in CoPiece;
  432.        if not good then outtextXY(380,170,'You can only jump an opponent');
  433.        end;
  434.  
  435.      if (not newmve) and (not good) then tosq := fmsq;
  436.     Until good;
  437.  
  438.     rw := 0;
  439.     if abs(fmsq.value-tosq.value)>7 then     {is it a jump?}
  440.      begin
  441.       outtextXY(350,150,'Multiple jump?');
  442.       ans := readkey;
  443.       HuMove := ans in ['Y','y'];
  444.       rw := (fmsq.value+tosq.value) div 2;
  445.       a[rw] := blnk;
  446.       j := 1;                                {remove the comp piece}
  447.       while checker[j]<>rw do inc(j);
  448.       if a[checker[j]]=CoKing then dec(KingCnt);
  449.       if j<compcnt then
  450.        for i := j to compcnt-1 do checker[i] := checker[i+1];
  451.       dec(compcnt);
  452.       inc(total);
  453.       if (tosq.value>68) and (fmsq.piece=HuMan)
  454.        then begin
  455.         newmve := true;
  456.         HuMove := false;
  457.        end                                   {reaching Kings row ends move}
  458.        else Newmve := false;
  459.       Njmp := false;
  460.      end
  461.      else
  462.       begin
  463.        HuMove := false;
  464.        Newmve := true;
  465.        Njmp := true;
  466.       end;
  467.     ShowMove;
  468.     if rw>0 then  placePiece(rw,blnk);
  469.   End;
  470.  
  471. Procedure disp_status;
  472.   Var
  473.     cnt:string;
  474.   Begin
  475.     bar(438,38,472,62);
  476.     SetTextStyle(Defaultfont,horizdir,2);
  477.     str(sum,cnt);
  478.     outtextXY(440,45,cnt);
  479.     bar(438,288,472,312);                     {show the score}
  480.     str(total,cnt);
  481.     outtextXY(440,293,cnt);
  482.     SetTextStyle(defaultfont,horizdir,1);
  483.     if (sum=12) or (total=12) then
  484.      begin
  485.       bar(335,90,630,270);                    {game over}
  486.       If sum=12 then
  487.         begin
  488.         SetTextstyle(defaultfont,horizdir,2);
  489.         OutTextXY(350,100,'I WIN!');
  490.         end;
  491.       if total=12 then OutTextXY(360,100,'You win.');
  492.       ans := readkey;
  493.       Closegraph;
  494.       halt;
  495.      end;
  496.   End;
  497.  
  498.  
  499. Procedure Comp_move;
  500.   Var
  501.     Q,z,i,d,j : integer;
  502.  
  503.   Procedure CrownKings;
  504.     Var z : integer;
  505.     Begin
  506.       for z := 69 to 72 do
  507.        if a[z]=Human then
  508.         begin
  509.          a[z] := HuKing;
  510.          placePiece(z,Huking);
  511.         end;
  512.       for z := 24 to 27 do
  513.        if a[z]=Coman then
  514.         begin
  515.          a[z] := CoKing;
  516.          inc(KingCnt);
  517.          placePiece(z,CoKing);
  518.         end;
  519.     End;
  520.  
  521.  
  522.   Procedure ChkHuman;
  523.     Var
  524.       i,Q :integer;
  525.     Begin
  526.       Q := 0;
  527.       for i := 24 to 72 do
  528.        if jmpchk[i] and (a[i] in HuPiece) then begin
  529.         OpChkJmp(Q,i);
  530.         if Q<>0 then begin
  531.          OuttextXY(350,140,'You missed a jump');
  532.          flash_piece(i);
  533.          flash_piece(i);
  534.          OuttextXY(355,150,'Hit any key to continue');
  535.          ans := readkey;
  536.          placepiece(i,blnk);
  537.          inc(sum);
  538.          disp_status;
  539.          exit;
  540.         end;
  541.        end;
  542.     End;
  543.  
  544.   Procedure ChkJmp(var Q:integer);
  545.     Var d : integer;
  546.     Begin
  547.       for d := 1 to 4 do              {comp piece [z] has a jump?}
  548.       begin
  549.        if (a[z]<>CoKing) and (d>2) then exit;
  550.        if (a[z+direc[d]] in HuPiece) and (a[z+2*direc[d]]=blnk)
  551.          then begin
  552.           Q := direc[d];
  553.           exit;
  554.        end;
  555.       end;
  556.       Q := 0;
  557.     End;
  558.  
  559.   Procedure Do_Jmp;
  560.     Var j : integer;
  561.     Begin
  562.       flash_piece(z);
  563.       placePiece(z+2*Q,a[z]);
  564.       j := 1;
  565.       While checker[j]<>z do inc(j);
  566.       placePiece(z,blnk);
  567.       checker[j] := z+2*Q;
  568.       inc(Sum);
  569.       placePiece(z+Q,blnk);
  570.     End;
  571.  
  572.   Procedure Do_Move(oldsq,amnt:integer);
  573.     Var i,nwsq : integer;
  574.     Begin
  575.       nwsq := oldsq + amnt;
  576.       flash_piece(oldsq);
  577.       placepiece(nwsq,a[oldsq]);
  578.       i := 1;
  579.       while checker[i]<>oldsq do inc(i);
  580.       checker[i] := nwsq;
  581.       placepiece(oldsq,blnk);
  582.     End;
  583.  
  584.   Procedure Random_move;
  585.     Var
  586.       z,d : integer;
  587.       n,j : word;
  588.       gmove : set of pieces;
  589.     Begin
  590.       n := compcnt;
  591.       use := checker;
  592.       while n>0 do
  593.        begin
  594.         j := 1 + Random(n);             {see if we can slide inbetween}
  595.         if j>n then j := n;
  596.         if j<1 then j := 1;
  597.         if (n>2) and (j=n) then dec(j);
  598.         z := use[j];
  599.         for d := 1 to 2 do
  600.          begin
  601.           if (a[z+direc[d]]=blnk) and (not (a[z+2*direc[d]] in HuPiece))
  602.             and (a[z-13]<>Blnk) and (a[z-1+2*(d mod 2)]<>Blnk)
  603.            then begin
  604.             Do_Move(z,direc[d]);
  605.             exit;
  606.            end;
  607.           if (a[z]=CoKing) and (z<55) and (a[z-direc[d]]=blnk)
  608.             and (not (a[z-2*direc[d]] in HuPiece))
  609.             and (a[z+13]<>Blnk) and (a[z-1+2*(d div 2)]<>Blnk)
  610.            then begin
  611.             Do_Move(z,-direc[d]);
  612.             exit;
  613.            end;
  614.          end;
  615.         use[j] := use[n];
  616.         dec(n);
  617.        end;
  618.       n := compcnt;
  619.       use := checker;
  620.       while n>0 do
  621.        begin
  622.         j := 1 + Random(n);
  623.         if j<1 then j := 1;
  624.         if j>n then j := n;
  625.         if (n>2) and (j=n) then dec(j);
  626.         z := use[j];
  627.         for d := 2 downto 1 do                 {otherwize not into a jump}
  628.          begin
  629.           if (a[z+direc[d]]=blnk)
  630.            and ((a[z]=CoMan) or (KingCnt=compcnt))
  631.            and (not (a[z+2*direc[d]] in HuPiece))
  632.            and (not (a[z+13] in HuPiece)) then
  633.            begin
  634.             Do_Move(z,direc[d]);
  635.             exit;
  636.            end;
  637.           if (kingcnt>compcnt-2) and (a[z]=CoKing) and (z<55)
  638.                      and (a[z-direc[d]]=blnk) and
  639.            (not (a[z-2*direc[d]] in HuPiece)) and (not (a[z-13] in HuPiece))
  640.            then begin
  641.             Do_Move(z,-direc[d]);
  642.             exit;
  643.            end;
  644.          end;
  645.         use[j] := use[n];
  646.         dec(n);
  647.        end;
  648.       n := compcnt;
  649.       use := checker;
  650.       while n>0 do
  651.        begin
  652.         j := 1 + Random(n);
  653.         if j>n then j := n;
  654.         if j<1 then j := 1;
  655.         if (n>2) and (j=n) then dec(j);
  656.         z := use[j];
  657.         for d := 1 to 2 do                 {otherwize just move}
  658.          begin
  659.           if (a[z+direc[d]]=blnk) then
  660.            begin
  661.             Do_Move(z,direc[d]);
  662.             exit;
  663.            end;
  664.           if (a[z]=CoKing) and (z<55) and (a[z-direc[d]]=blnk)
  665.            then begin
  666.             Do_Move(z,-direc[d]);
  667.             exit;
  668.            end;
  669.          end;
  670.         use[j] := use[n];
  671.         dec(n);
  672.        end;
  673.       OuttextXY(350,100,'I concede');
  674.       ans := readkey;                      {or give up}
  675.       closegraph;                          {game over}
  676.       halt;
  677.     End;
  678.  
  679.   Begin
  680.     CrownKings;
  681.     bar(335,90,630,270);
  682.     OutTextXY(350,110,'MY Move..');
  683.     delay(1000);                     {gives player a chance to look at screen}
  684.  
  685. {    outtextXY(355,120,'Hit any key');
  686.     ans := readkey; }        {alternate form for beginning computer move}
  687.  
  688.  
  689.     if Njmp then ChkHuman;            {check for missed jumps}
  690.     i := 1;Q :=0;
  691.     while (Q=0) and (i<=compcnt) do
  692.      begin
  693.       z := checker[i];
  694.       ChkJmp(Q);inc(i);               {can the computer jump?}
  695.      end;
  696.     if Q<>0
  697.      then while Q<>0 do begin
  698.       Do_Jmp;
  699.       z := z+2*Q;
  700.       Q := 0;                         {yes, do it}
  701.       ChkJmp(Q);                      {and check for more}
  702.      end
  703.      else begin
  704.       i := 1;
  705.       while (Q=0) and (i<=compcnt) do
  706.        begin
  707.         d := 1;                         {check for blocking jump}
  708.         z := checker[i];
  709.         repeat
  710.           j := direc[d];
  711.            if (a[z+j] in HuPiece) and (a[z-j]=blnk) then
  712.             begin
  713.              if (a[z-2*j] in CoPiece)
  714.               then Q := z-2*j
  715.               else if (a[z+13] in CoPiece) then
  716.                begin
  717.                 Q := z+13;
  718.                 j := direc[ (d mod 2) +1 ];
  719.                end;
  720.              end;
  721.           if (Q=0) and (a[z+2*j]=CoKing) then
  722.            begin
  723.             j := -j;
  724.             if (a[z+j] in HuPiece) and (a[z-j]=blnk)
  725.               then Q := z-2*j;
  726.            end;
  727.           inc(d);
  728.         until (Q<>0) or (d>2);
  729.         inc(i);
  730.        end;
  731.       if Q<>0
  732.        then Do_Move(Q,j)
  733.        else begin
  734.         i := 1;
  735.         while (Q=0) and (i<=compcnt) do
  736.          begin
  737.           z := checker[i];
  738.           if a[z]=CoKing then
  739.            begin
  740.             d := 3;
  741.             repeat                       {can you use the king?}
  742.              j := direc[d];
  743.              if (a[z+j]=blnk) and (a[z+2*j]=HuMan)
  744.               and (a[z+3*j]=blnk) then
  745.                if (not (a[z-1+2*((d-2) div 2)] in Hupiece))
  746.                 then Q := z;
  747.              inc(d);
  748.             until (Q<>0) or (d>4);
  749.            end;
  750.           inc(i);
  751.          end;
  752.         if Q<>0
  753.          then Do_Move(Q,j)
  754.          else Random_move;                {else random move}
  755.         end;
  756.       end;
  757.     for i := 24 to 72 do
  758.       if not (a[i] in HuPiece)
  759.        then jmpchk[i] := false
  760.        else begin
  761.         Q := 0;
  762.         OpChkJmp(Q,i);                {set check array for human jumps}
  763.         jmpchk[i] := Q<>0;
  764.        end;
  765.     Disp_status;
  766.     HuMove := true;
  767.     CrownKings;
  768.     Nmove := true;
  769.   End;
  770.  
  771. Procedure Play_game;
  772.   Var
  773.     forever : boolean;
  774.   Begin
  775.     forever := false;
  776.     repeat
  777.      if Humove then Player_move(Nmove);
  778.      disp_status;
  779.      if not Humove then Comp_move;
  780.     until forever;
  781.   End;
  782.  
  783.  
  784. BEGIN
  785.   Set_board;
  786.   Who_first;
  787.   Draw_board;
  788.   Nmove := true;
  789.   Randomize;
  790.   Play_game;
  791. END.
  792.